<template>
  <layout>
    <!-- 顶部操作 -->
    <section slot="search">
      <custom-form
        ref="search-form"
        class="search-form"
        v-model="tableSearch"
        layout="inline"
        :FormList="searchColumns"
      >
        <a-button
          class="action-button"
          type="primary"
          @click="search()"
        >搜索</a-button>
        <a-button
          class="action-button"
          type="primary"
          @click="handlerTableAdd"
        >新增</a-button>
      </custom-form>

      <!-- <a-input placeholder="产品名称或者编号" v-model="tableSearch.searchKey" allowClear style="width: 200px;" /> -->
    </section>

    <!-- 产品列表 -->
    <a-table
      :dataSource="tableData"
      :columns="tableColumns"
      :rowKey="record => record.usr_id"
      :customRow="customTableRow"
      :pagination="false"
      bordered
    >
      <template
        slot="big_mb_type"
        slot-scope="row"
      >
        {{getLabel(row.big_mb_type, [], 'big_mb_type')}}
      </template>
      <template
        slot="member_sex"
        slot-scope="row"
      >
        {{getLabel(row.member_sex, [], 'member_sex')}}
      </template>
      <template
        slot="big_mb_bank_code"
        slot-scope="row"
      >
        {{getLabel(row.big_mb_bank_code, [], 'big_mb_bank_code')}}
      </template>
      <!-- 按钮区 -->
      <template
        slot="action"
        slot-scope="row"
      >
        <a-button
          class="action-button"
          type="primary"
          size="small"
          @click="handleTableEdit(row)"
        >编辑</a-button>
        <a-popconfirm
          title="您确认要删除该条数据?"
          ok-text="确认"
          cancel-text="取消"
          @confirm="tableDel(row)"
        >
          <a-button
            class="action-button"
            type="danger"
            size="small"
          >删除</a-button>
        </a-popconfirm>
        <!-- <a-popconfirm
          title="您确认要删除该条数据?"
          ok-text="确认"
          cancel-text="取消"
          @confirm="tableDel(row)"
        >
          <a-button
            class="action-button"
            type="danger"
            size="small"
          >删除</a-button>
        </a-popconfirm> -->
        <!-- <a-button
          class="action-button"
          type="primary"
          size="small"
          @click="handleTableEdit(row)"
        >项目管理</a-button> -->
      </template>
    </a-table>

    <!-- 产品列表分页器 -->
    <a-pagination
      slot="paging"
      :pageSizeOptions="pageSizes"
      :total="total"
      showSizeChanger
      :pageSize="pageSize"
      v-model="currentPage"
      @showSizeChange="changePageSize"
      @change="changePage"
    >
    </a-pagination>

    <!-- 编辑产品数据 -->
    <a-modal
      :visible="visible"
      :title="visibleTitle"
      centered
      @cancel="visible = false"
      @ok="handleSubmit"
    >
      <custom-form
        ref="custom-form"
        class="custom-form"
        v-model="currentRow"
        :FormList="formColumns"
        :mode="customMode"
        v-bind="formItemLayout"
        layout="horizontal"
      ></custom-form>
    </a-modal>

  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import { State, Mutation, Getter, namespace } from 'vuex-class'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { userServices, IAdmin } from '@/common/services'
import { largeMemberServices, ILargeMember } from '@/common/services/largeMember'
import { commonServices } from '@/common/services/common'
import { memberRole, LargeMemberType } from '@/common/enum'

@Component({
  components: {
    Layout: TableLayout,
    CustomForm
  }
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: String
  })
  public currentAreaId!: string

  public commonParams = {
    s_a_id: ''
  }

  // 产品列表搜索条件
  public tableSearch = {}

  // 自定义mode
  public customMode = ''

  // 产品列表表格信息
  public columns: ITable.IColumn[] = [
    {
      title: '大户编号',
      dataIndex: 'big_mb_id',
      key: 'big_mb_id',
      width: 120,
      form: {
        type: 'a-input',
        placeholder: '编号自动生成',
        disabled: true
      }
    },
    {
      title: '大户名称',
      dataIndex: 'big_mb_nam',
      key: 'big_mb_nam',
      form: {
        type: 'a-input',
        placeholder: '请输入大户名称',
        isShowQuery: true
      }
    },
    {
      title: '大户类型',
      key: 'big_mb_type',
      scopedSlots: { customRender: 'big_mb_type' },
      form: {
        type: 'a-select',
        placeholder: '请选择大户类型',
        dict: LargeMemberType
      }
    },
    {
      title: '法定编码',
      dataIndex: 'big_mb_law_id',
      key: 'big_mb_law_id',
      form: {
        type: 'a-input',
        placeholder: '请输入法定编码'
      }
    },
    {
      title: '注册地址',
      dataIndex: 'big_mb_addr',
      key: 'big_mb_addr',
      form: {
        type: 'a-input',
        placeholder: '请输入注册地址'
      }
    },
    {
      title: '银行卡号',
      dataIndex: 'big_mb_bank_id',
      key: 'big_mb_bank_id',
      form: {
        type: 'a-input',
        placeholder: '请输入银行卡号'
      }
    },
    {
      title: '开户名',
      dataIndex: 'big_mb_band_user',
      key: 'big_mb_band_user',
      form: {
        type: 'a-input',
        placeholder: '请输入开户名'
      }
    },
    {
      title: '开户行',
      key: 'big_mb_bank_code',
      scopedSlots: { customRender: 'big_mb_bank_code' },
      form: {
        type: 'a-auto-complete',
        placeholder: '请选择/输入开户银行',
        showSearch: true,
        dataSource: []
      }
    },
    {
      title: '法人',
      dataIndex: 'big_mb_user',
      key: 'big_mb_user',
      form: {
        type: 'a-input',
        placeholder: '请输入法人'
      }
    },
    {
      title: '联系人',
      dataIndex: 'big_mb_contact',
      key: 'big_mb_contact',
      form: {
        type: 'a-input',
        placeholder: '请输入联系人'
      }
    },
    {
      title: '联系电话',
      dataIndex: 'big_mb_tel',
      key: 'big_mb_tel',
      form: {
        type: 'a-input',
        placeholder: '请输入联系电话'
      }
    },
    {
      title: '操作',
      key: 'action',
      width: 180,
      fixed: 'right',
      scopedSlots: { customRender: 'action' }
    }
  ]

  public tableApi = {
    list: largeMemberServices.getLargeMemberList,
    add: largeMemberServices.updateLargeMember,
    edit: largeMemberServices.updateLargeMember,
    del: largeMemberServices.deleteLargeMember
    // imageUpload: 'uploadStoreImage',
    // imageRemove: 'delStoreImage'
  }

  @Watch('currentAreaId')
  public handlerCurrentAreaIdChange() {
    this.commonParams.s_a_id = this.currentAreaId
    this.getData()
  }

  public mounted() {
    this.getBankTypes()
  }

  public async getData() {
    const res = await this.getTableList()
  }

  public getBankTypes() {
    commonServices.getBankType().then(res => {
      const dict = []
      this.changeDict(
        'big_mb_bank_code',
        Object.keys(res.data).map(key => res.data[key]),
        'dataSource'
      )
    })
  }

  public handlerTableAdd() {
    this.tableAdd()
    this.$nextTick(() => {
      this.currentRow = Object.assign({}, { s_a_id: this.currentAreaId })
    })
  }

  // 编辑前数据预处理
  public async handleTableEdit(row: ILargeMember) {
    this.tableEdit(Object.assign({}, row))
  }
}
</script>

<style scoped>
.action-button {
  margin: 0px 10px 0px 10px;
}
.form-item-class {
  margin-bottom: 0px;
}
.img-box {
  width: 100px;
  height: 100px;
  margin: 10px;
}
.item-blue {
  color: #1989fa;
}
</style>
